package cn.itsource.org.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.mapper.ShopMapper;
import cn.itsource.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
/*
    事务：ACID属性

 */
public class ShopServiceImpl extends BaseServiceImpl<Shop>
        implements IShopService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private ShopMapper shopMapper;

    @Override
    @Transactional
    public void settledIn(Shop shop) {
        try {
            //1.保存employee对象
            Employee admin = shop.getAdmin();
            System.out.println("保存之前："+admin.getId());
            employeeMapper.save(admin);
            System.out.println("保存之后："+admin.getId());
            //保存shop对象
            shopMapper.save(shop);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
